home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 February: Technology Seed / Mac Tech Seed Feb '97.toast / ODF Release 3 / ODFDev / ODF / OS / FWMenu / FWMnuItm.cpp < prev    next >
Encoding:
Text File  |  1996-12-16  |  23.0 KB  |  723 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWMnuItm.cpp
  4. //    Release Version:    $ ODF 3 $
  5. //
  6. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "FWOS.hpp"
  11.  
  12. #ifndef FWMNUITM_H
  13. #include "FWMnuItm.h"
  14. #endif
  15.  
  16. #ifndef FWMENUS_K
  17. #include "FWMenus.k"
  18. #endif
  19.  
  20. #ifndef FWPULLDM_H
  21. #include "FWPullDM.h"
  22. #endif
  23.  
  24. #ifndef FWMNUBAR_H
  25. #include "FWMnuBar.h"
  26. #endif
  27.  
  28. // ----- Foundation Includes -----
  29.  
  30. #ifndef FWSTREAM_H
  31. #include "FWStream.h"
  32. #endif
  33.  
  34. #ifndef FWSTRING_H
  35. #include "FWString.h"
  36. #endif
  37.  
  38. // ----- OpenDoc Utility Includes -----
  39.  
  40. #ifndef _ITEXT_
  41. #include "IText.h"
  42. #endif
  43.  
  44. // ----- OpenDoc Includes -----
  45.  
  46. #ifndef SOM_ODMenuBar_xh
  47. #include <MenuBar.xh>
  48. #endif
  49.  
  50. // ----- Macintosh Includes -----
  51.  
  52. #if defined(FW_BUILD_MAC) && !defined(__SCRIPT__)
  53. #include <Script.h>
  54. #endif
  55.  
  56. //========================================================================================
  57. // File scope definitions
  58. //========================================================================================
  59.  
  60. #ifdef FW_BUILD_MAC
  61. #pragma segment fwmenu
  62. #endif
  63.  
  64. //========================================================================================
  65. //    Template Instantiations
  66. //========================================================================================
  67.  
  68. #include "FWTColl.tpp"
  69.  
  70. FW_DEFINE_AUTO_TEMPLATE(FW_TOrderedCollectionIterator, FW_CMenuItem)
  71. FW_DEFINE_AUTO_TEMPLATE(FW_TOrderedCollection, FW_CMenuItem)
  72.  
  73. #ifdef FW_USE_TEMPLATE_PRAGMAS
  74.     #pragma template_access public
  75.     #pragma template FW_TOrderedCollection<FW_CMenuItem>
  76.     #pragma template FW_TOrderedCollectionIterator<FW_CMenuItem>
  77. #else
  78.     template class FW_TOrderedCollection<FW_CMenuItem>;
  79.     template class FW_TOrderedCollectionIterator<FW_CMenuItem>;
  80. #endif
  81.  
  82. //========================================================================================
  83. //    class FW_CMenuItem
  84. //========================================================================================
  85.  
  86. FW_DEFINE_AUTO(FW_CMenuItem)
  87. FW_DEFINE_CLASS_M0(FW_CMenuItem)
  88.  
  89. // This class is archivable, but we provide the archiving implementation in a separate
  90. // translation unit in order to enable deadstripping of the archiving-related code
  91. // in parts that do not use archiving with this class.
  92.  
  93. //----------------------------------------------------------------------------------------
  94. //    FW_CMenuItem::FW_CMenuItem
  95. //----------------------------------------------------------------------------------------
  96.  
  97. FW_CMenuItem::FW_CMenuItem(Environment* ev, FW_CReadableStream& stream) :
  98.     fOwnerMenu(NULL),
  99.     fIndex(0)
  100. #ifdef FW_BUILD_MAC
  101.     ,fCommandID(FW_kNoCommand)
  102. #endif
  103. {
  104. FW_UNUSED(ev);
  105.     stream >> fIndex;
  106.     FW_READ_DYNAMIC_OBJECT(stream, &fOwnerMenu, FW_CPullDownMenu);
  107.     FW_END_CONSTRUCTOR
  108. }
  109.  
  110. //----------------------------------------------------------------------------------------
  111. //    FW_CMenuItem::FW_CMenuItem
  112. //----------------------------------------------------------------------------------------
  113.  
  114. FW_CMenuItem::FW_CMenuItem(Environment* ev, FW_CPullDownMenu* ownerMenu, short index) :
  115.     fOwnerMenu(ownerMenu), 
  116.     fIndex(index)
  117. #ifdef FW_BUILD_MAC
  118.     ,fCommandID(FW_kNoCommand)
  119. #endif
  120. {
  121. FW_UNUSED(ev);
  122.     FW_ASSERT(ownerMenu != NULL);
  123.     FW_ASSERT(index > 0);
  124.     FW_END_CONSTRUCTOR
  125. }
  126.  
  127. //----------------------------------------------------------------------------------------
  128. //    FW_CMenuItem::~FW_CMenuItem
  129. //----------------------------------------------------------------------------------------
  130.  
  131. FW_CMenuItem::~FW_CMenuItem()
  132. {
  133.     FW_START_DESTRUCTOR
  134. }
  135.  
  136. //----------------------------------------------------------------------------------------
  137. //    FW_CMenuItem::GetCommandID
  138. //----------------------------------------------------------------------------------------
  139.  
  140. ODCommandID FW_CMenuItem::GetCommandID(Environment* ev) const
  141. {
  142. FW_UNUSED(ev);
  143.     FW_ASSERT(fOwnerMenu != NULL);
  144.  
  145. #ifdef FW_BUILD_MAC
  146.     return fCommandID;
  147. #endif
  148.     
  149. #ifdef FW_BUILD_WIN
  150.     return fOwnerMenu->GetCommandID(ev, fIndex);
  151. #endif
  152. }
  153.  
  154. //----------------------------------------------------------------------------------------
  155. //    FW_CMenuItem::PrivGetMenuItem
  156. //----------------------------------------------------------------------------------------
  157.  
  158. FW_CMenuItem* FW_CMenuItem::PrivGetMenuItem(Environment* ev, ODCommandID commandID) const
  159. {
  160. FW_UNUSED(ev);
  161. FW_UNUSED(commandID);
  162.     return NULL;
  163. }
  164.  
  165. //----------------------------------------------------------------------------------------
  166. //    FW_CMenuItem::PrivFindMenuWithID
  167. //----------------------------------------------------------------------------------------
  168.  
  169. FW_CPullDownMenu* FW_CMenuItem::PrivFindMenuWithID(Environment* ev, ODMenuID menuID) const
  170. {
  171. FW_UNUSED(ev);
  172. FW_UNUSED(menuID);
  173.     return NULL;
  174. }
  175.  
  176. //----------------------------------------------------------------------------------------
  177. //    FW_CMenuItem::PrivDisableAll
  178. //----------------------------------------------------------------------------------------
  179.  
  180. void FW_CMenuItem::PrivDisableAll(Environment* ev)
  181. {
  182. FW_UNUSED(ev);
  183.     // Nothing to do on the Mac because FW_CPullDownMenu::DisableAll disables all its items
  184.     // at once
  185.     
  186. #if defined(FW_BUILD_WIN) && 0
  187.     // [jkp] need to rework menus
  188.     HMENU hMenu = fOwnerMenu->GetPlatformMenu(ev);
  189.     ::EnableMenuItem(hMenu, fIndex - 1, MF_BYPOSITION | MF_DISABLED | MF_GRAYED);
  190. #endif
  191. }
  192.  
  193. //----------------------------------------------------------------------------------------
  194. //    FW_CMenuItem::PrivEnableAll
  195. //----------------------------------------------------------------------------------------
  196.  
  197. void FW_CMenuItem::PrivEnableAll(Environment* ev)
  198. {
  199. FW_UNUSED(ev);
  200.     // Nothing to do on the Mac because FW_CPullDownMenu::EnableAll enables all its items
  201.     // at once
  202.     
  203. #if defined(FW_BUILD_WIN) && 0
  204.     // [jkp] need to rework menus
  205.     HMENU hMenu = fOwnerMenu->GetPlatformMenu(ev);
  206.     ::EnableMenuItem(hMenu, fIndex - 1, MF_BYPOSITION | MF_ENABLED);
  207. #endif
  208. }
  209.  
  210. //----------------------------------------------------------------------------------------
  211. //    FW_CMenuItem::PrivAttach
  212. //----------------------------------------------------------------------------------------
  213.  
  214. void FW_CMenuItem::PrivAttach(Environment* ev, FW_CMenuBar* menuBar)
  215. {
  216. FW_UNUSED(ev);
  217. FW_UNUSED(menuBar);
  218.     // Nothing to do 
  219. }
  220.  
  221. //----------------------------------------------------------------------------------------
  222. //    FW_CMenuItem::PrivDetach
  223. //----------------------------------------------------------------------------------------
  224.  
  225. void FW_CMenuItem::PrivDetach(Environment* ev, FW_CMenuBar* menuBar)
  226. {
  227. FW_UNUSED(ev);
  228. FW_UNUSED(menuBar);
  229.     // Nothing to do 
  230. }
  231.  
  232. //----------------------------------------------------------------------------------------
  233. //    FW_CMenuItem::Flatten
  234. //----------------------------------------------------------------------------------------
  235.  
  236. void FW_CMenuItem::Flatten(Environment* ev, FW_CWritableStream& stream)
  237. {
  238. FW_UNUSED(ev);
  239.     FW_WRITE_DYNAMIC_OBJECT(stream, fOwnerMenu, FW_CPullDownMenu);
  240. }
  241.  
  242. //========================================================================================
  243. //    class FW_CSeparatorItem
  244. //========================================================================================
  245.  
  246. FW_DEFINE_AUTO(FW_CSeparatorItem)
  247. FW_DEFINE_CLASS_M1(FW_CSeparatorItem, FW_CMenuItem)
  248.  
  249. // This class is archivable, but we provide the archiving implementation in a separate
  250. // translation unit in order to enable deadstripping of the archiving-related code
  251. // in parts that do not use archiving with this class.
  252.  
  253. //----------------------------------------------------------------------------------------
  254. //    FW_CSeparatorItem::FW_CSeparatorItem
  255. //----------------------------------------------------------------------------------------
  256.  
  257. FW_CSeparatorItem::FW_CSeparatorItem(Environment* ev, FW_CReadableStream& stream) :
  258.     FW_CMenuItem(ev, stream)
  259. {    
  260.     InitSeparator(ev, fOwnerMenu->GetPlatformMenu(ev));
  261.     FW_END_CONSTRUCTOR
  262. }
  263.  
  264. //----------------------------------------------------------------------------------------
  265. //    FW_CSeparatorItem::FW_CSeparatorItem
  266. //----------------------------------------------------------------------------------------
  267.  
  268. FW_CSeparatorItem::FW_CSeparatorItem(Environment* ev, FW_CPullDownMenu* ownerMenu, short index) :
  269.     FW_CMenuItem(ev, ownerMenu, index)
  270. {
  271.     InitSeparator(ev, ownerMenu->GetPlatformMenu(ev));
  272.     FW_END_CONSTRUCTOR
  273. }
  274.  
  275. //----------------------------------------------------------------------------------------
  276. //    FW_CSeparatorItem::~FW_CSeparatorItem
  277. //----------------------------------------------------------------------------------------
  278.  
  279. FW_CSeparatorItem::~FW_CSeparatorItem()
  280. {
  281.     FW_START_DESTRUCTOR
  282. }
  283.  
  284. //----------------------------------------------------------------------------------------
  285. //    FW_CSeparatorItem::InitSeparator
  286. //----------------------------------------------------------------------------------------
  287.  
  288. void FW_CSeparatorItem::InitSeparator(Environment* ev, const ODPlatformMenu& platformMenu)
  289. {
  290. FW_UNUSED(ev);
  291. #ifdef FW_BUILD_MAC
  292.     fCommandID = FW_kSeparatorCommand;
  293.     ::InsertMenuItem(platformMenu, "\p-", fIndex - 1);
  294. #endif
  295.  
  296. #if defined(FW_BUILD_WIN) && 0
  297.     // [jkp] need to rework menus
  298.     ::InsertMenu(platformMenu, fIndex, MF_BYPOSITION | MF_SEPARATOR, 0, NULL);
  299. #endif
  300. }
  301.  
  302. //----------------------------------------------------------------------------------------
  303. //    FW_CSeparatorItem::PrivDisableAll
  304. //----------------------------------------------------------------------------------------
  305.  
  306. void FW_CSeparatorItem::PrivDisableAll(Environment* ev)
  307. {
  308. FW_UNUSED(ev);
  309.     // Nothing to do. Already disabled
  310. }
  311.  
  312. //----------------------------------------------------------------------------------------
  313. //    FW_CSeparatorItem::PrivEnableAll
  314. //----------------------------------------------------------------------------------------
  315.  
  316. void FW_CSeparatorItem::PrivEnableAll(Environment* ev)
  317. {
  318. FW_UNUSED(ev);
  319.     // Should never enable it
  320. }
  321.  
  322. //========================================================================================
  323. //    class FW_CTextItem
  324. //========================================================================================
  325.  
  326. FW_DEFINE_AUTO(FW_CTextItem)
  327. FW_DEFINE_CLASS_M1(FW_CTextItem, FW_CMenuItem)
  328.  
  329. // This class is archivable, but we provide the archiving implementation in a separate
  330. // translation unit in order to enable deadstripping of the archiving-related code
  331. // in parts that do not use archiving with this class.
  332.  
  333. //----------------------------------------------------------------------------------------
  334. //    FW_CTextItem::FW_CTextItem
  335. //----------------------------------------------------------------------------------------
  336.  
  337. FW_CTextItem::FW_CTextItem(Environment* ev, FW_CReadableStream& stream) :
  338.     FW_CMenuItem(ev, stream)
  339. {
  340.     ODCommandID commandID;
  341.     stream >> commandID;
  342.     
  343.     FW_MenuKey menuKey;
  344.     stream >> menuKey;
  345.     
  346.     FW_CString text;
  347.     stream >> text;
  348.     
  349.     PrivInitTextItem(ev, fOwnerMenu->GetPlatformMenu(ev), text, commandID, menuKey);
  350.     FW_END_CONSTRUCTOR
  351. }
  352.  
  353. //----------------------------------------------------------------------------------------
  354. //    FW_CTextItem::FW_CTextItem
  355. //----------------------------------------------------------------------------------------
  356.  
  357. FW_CTextItem::FW_CTextItem(Environment* ev,
  358.                         FW_CPullDownMenu* ownerMenu, 
  359.                         short index,            
  360.                         const FW_CString& text,
  361.                         ODCommandID commandID,
  362.                         FW_MenuKey menuKey) :
  363.     FW_CMenuItem(ev, ownerMenu, index)
  364. {
  365.     FW_ASSERT(commandID > 0);
  366.     PrivInitTextItem(ev, ownerMenu->GetPlatformMenu(ev), text, commandID, menuKey);
  367.     FW_END_CONSTRUCTOR
  368. }
  369.  
  370. //----------------------------------------------------------------------------------------
  371. //    FW_CTextItem::~FW_CTextItem
  372. //----------------------------------------------------------------------------------------
  373.  
  374. FW_CTextItem::~FW_CTextItem()
  375. {
  376.     FW_START_DESTRUCTOR
  377. }
  378.  
  379. //----------------------------------------------------------------------------------------
  380. //    FW_CTextItem::PrivInitTextItem
  381. //----------------------------------------------------------------------------------------
  382.  
  383. void FW_CTextItem::PrivInitTextItem(Environment* ev,
  384.                               const ODPlatformMenu&    platformMenu,
  385.                               const FW_CString& text,
  386.                               ODCommandID commandID,
  387.                               FW_MenuKey menuKey)
  388. {
  389. FW_UNUSED(ev);
  390.     FW_ASSERT(commandID >= FW_kFirstUserCommandID);
  391.     
  392. #ifdef FW_BUILD_MAC
  393.     fCommandID = commandID;
  394.     
  395.     Str255 str;
  396.     text.ExportPascal(str);
  397.     ::InsertMenuItem(platformMenu, "\pabc", fIndex - 1);
  398.     ::SetMenuItemText(platformMenu, fIndex, str);
  399.     
  400.     ODScriptCode systemScriptCode = (ODScriptCode) ::GetScriptManagerVariable(smSysScript);
  401.     FW_Locale locale;
  402.     text.GetLocale(locale);
  403.     if (locale.fScriptCode != systemScriptCode)
  404.     {    // set this menu item's script code
  405.         ::SetItemCmd(platformMenu, fIndex, FW_kPrivMacScriptCodeKeyEquivalent);
  406.         ::SetItemIcon(platformMenu, fIndex, locale.fScriptCode);
  407.         menuKey = FW_kNoKeyEquivalent;    // so that code below doesn't mess up the key field we just set
  408.     }
  409.     
  410.     if (menuKey != FW_kNoKeyEquivalent)
  411.         ::SetItemCmd(platformMenu, fIndex, menuKey & FW_kPrivMacMenuKeyCharMask);
  412. #endif
  413.  
  414. #if defined(FW_BUILD_WIN) && 0
  415.     // [jkp] need to rework menus
  416.     char szText[256];
  417.     text.ExportCString(szText);
  418.     ::InsertMenu(platformMenu, fIndex, MF_BYPOSITION | MF_STRING | MF_DISABLED | MF_UNCHECKED, commandID, szText);
  419.     //::AppendMenu(platformMenu.menu, MF_STRING | MF_DISABLED | MF_UNCHECKED, commandID, text);
  420.     
  421.     // [HLX] No way yet to build accelerator table
  422. FW_UNUSED(menuKey);
  423. #endif
  424. }
  425.  
  426. #ifdef FW_BUILD_MAC
  427. //----------------------------------------------------------------------------------------
  428. //    FW_CTextItem::PrivAttach
  429. //----------------------------------------------------------------------------------------
  430.  
  431. void FW_CTextItem::PrivAttach(Environment* ev, FW_CMenuBar* menuBar)
  432. {
  433.     menuBar->PrivMacRegisterCommand(ev, fCommandID, fOwnerMenu->GetMenuID(ev), fIndex);
  434. }
  435. #endif
  436.  
  437. #ifdef FW_BUILD_MAC
  438. //----------------------------------------------------------------------------------------
  439. //    FW_CTextItem::PrivDetach
  440. //----------------------------------------------------------------------------------------
  441.  
  442. void FW_CTextItem::PrivDetach(Environment* ev, FW_CMenuBar* menuBar)
  443. {
  444.     menuBar->PrivMacUnregisterCommand(ev, fCommandID);
  445. }
  446. #endif
  447.  
  448. //----------------------------------------------------------------------------------------
  449. //    FW_CTextItem::Flatten
  450. //----------------------------------------------------------------------------------------
  451.  
  452. void FW_CTextItem::Flatten(Environment* ev, FW_CWritableStream& stream)
  453. {
  454.     FW_CMenuItem::Flatten(ev, stream);
  455.     
  456.     FW_CMenuBar* menuBar = fOwnerMenu->GetMenuBar(ev);
  457.     
  458.     ODCommandID commandID = GetCommandID(ev);
  459.     stream << commandID;
  460.  
  461.     FW_MenuKey menuKey = menuBar->GetMenuKey(ev, commandID);
  462.     stream << menuKey;
  463.  
  464.     FW_CString text;
  465.     menuBar->GetItemString(ev, commandID, text);
  466.     stream << text;
  467. }
  468.  
  469. //========================================================================================
  470. //    class FW_CToggleItem
  471. //========================================================================================
  472.  
  473. FW_DEFINE_AUTO(FW_CToggleItem)
  474. FW_DEFINE_CLASS_M1(FW_CToggleItem, FW_CTextItem)
  475.  
  476. // This class is archivable, but we provide the archiving implementation in a separate
  477. // translation unit in order to enable deadstripping of the archiving-related code
  478. // in parts that do not use archiving with this class.
  479.  
  480. //----------------------------------------------------------------------------------------
  481. //    FW_CToggleItem::FW_CToggleItem
  482. //----------------------------------------------------------------------------------------
  483.  
  484. FW_CToggleItem::FW_CToggleItem(Environment* ev, FW_CReadableStream& stream) :
  485.     FW_CTextItem(ev, stream),
  486.     fToggleState(true)
  487. {
  488.     stream >> fOtherText;
  489.     FW_END_CONSTRUCTOR
  490. }
  491.  
  492. //----------------------------------------------------------------------------------------
  493. //    FW_CToggleItem::FW_CToggleItem
  494. //----------------------------------------------------------------------------------------
  495.  
  496. FW_CToggleItem::FW_CToggleItem(Environment* ev,
  497.                         FW_CPullDownMenu* ownerMenu, 
  498.                         short index,            
  499.                         const FW_CString& trueText,
  500.                         const FW_CString& falseText,
  501.                         ODCommandID commandID,
  502.                         FW_MenuKey menuKey) :
  503.     FW_CTextItem(ev, ownerMenu, index, trueText, commandID, menuKey),
  504.     fToggleState(true)
  505. {
  506.     fOtherText = falseText;
  507.     FW_END_CONSTRUCTOR
  508. }
  509.  
  510. //----------------------------------------------------------------------------------------
  511. //    FW_CToggleItem::~FW_CToggleItem
  512. //----------------------------------------------------------------------------------------
  513.  
  514. FW_CToggleItem::~FW_CToggleItem()
  515. {
  516.     FW_START_DESTRUCTOR
  517. }
  518.  
  519. //----------------------------------------------------------------------------------------
  520. //    FW_CToggleItem::ToggleItem
  521. //----------------------------------------------------------------------------------------
  522.  
  523. void FW_CToggleItem::ToggleItem(Environment* ev, FW_Boolean newState)
  524. {
  525.     if (newState == fToggleState)
  526.         return;
  527.     
  528.     FW_CMenuBar* menuBar = fOwnerMenu->GetMenuBar(ev);
  529.     
  530.     FW_CString currentText;
  531.     menuBar->GetItemString(ev, GetCommandID(ev), currentText);
  532.         
  533.     fToggleState = newState;
  534.     
  535.     menuBar->SetItemString(ev, GetCommandID(ev), fOtherText);
  536.     
  537.     fOtherText = currentText;
  538. }
  539.  
  540. //----------------------------------------------------------------------------------------
  541. //    FW_CToggleItem::Flatten
  542. //----------------------------------------------------------------------------------------
  543.  
  544. void FW_CToggleItem::Flatten(Environment* ev, FW_CWritableStream& stream)
  545. {
  546.     FW_CTextItem::Flatten(ev, stream);
  547.     
  548.     stream << fOtherText;
  549. }
  550.  
  551. //========================================================================================
  552. //    class FW_CSubMenuItem
  553. //========================================================================================
  554.  
  555. FW_DEFINE_AUTO(FW_CSubMenuItem)
  556. FW_DEFINE_CLASS_M1(FW_CSubMenuItem, FW_CMenuItem)
  557.  
  558. // This class is archivable, but we provide the archiving implementation in a separate
  559. // translation unit in order to enable deadstripping of the archiving-related code
  560. // in parts that do not use archiving with this class.
  561.  
  562. //----------------------------------------------------------------------------------------
  563. //    FW_CSubMenuItem::FW_CSubMenuItem
  564. //----------------------------------------------------------------------------------------
  565.  
  566. FW_CSubMenuItem::FW_CSubMenuItem(Environment* ev, FW_CReadableStream& stream) :
  567.     FW_CMenuItem(ev, stream)
  568. {
  569.     FW_READ_DYNAMIC_OBJECT(stream, &fSubMenu, FW_CPullDownMenu);
  570.     
  571.     PrivInitSubMenu(ev, fOwnerMenu->GetPlatformMenu(ev));
  572.     FW_END_CONSTRUCTOR
  573. }
  574.  
  575. //----------------------------------------------------------------------------------------
  576. //    FW_CSubMenuItem::FW_CSubMenuItem
  577. //----------------------------------------------------------------------------------------
  578.  
  579. FW_CSubMenuItem::FW_CSubMenuItem(Environment* ev,
  580.                 FW_CPullDownMenu* ownerMenu, 
  581.                 short index,
  582.                 FW_CPullDownMenu* adoptSubMenu):
  583.     FW_CMenuItem(ev, ownerMenu, index),
  584.     fSubMenu(adoptSubMenu)
  585. {
  586.     FW_ASSERT(adoptSubMenu != NULL);
  587.     PrivInitSubMenu(ev, ownerMenu->GetPlatformMenu(ev));
  588.     FW_END_CONSTRUCTOR
  589. }
  590.  
  591. //----------------------------------------------------------------------------------------
  592. //    FW_CSubMenuItem::~FW_CSubMenuItem
  593. //----------------------------------------------------------------------------------------
  594.  
  595. FW_CSubMenuItem::~FW_CSubMenuItem()
  596. {
  597.     FW_START_DESTRUCTOR
  598.     delete fSubMenu;
  599.     fSubMenu = NULL;
  600. }
  601.  
  602. //----------------------------------------------------------------------------------------
  603. //    FW_CSubMenuItem::PrivInitSubMenu
  604. //----------------------------------------------------------------------------------------
  605.  
  606. void FW_CSubMenuItem::PrivInitSubMenu(Environment* ev, const ODPlatformMenu& platformMenu)
  607. {
  608.     const ODPlatformMenu& subPlatformMenu = fSubMenu->GetPlatformMenu(ev);
  609.  
  610. #ifdef FW_BUILD_MAC
  611.     fSubMenu->SetParentMenuItem(ev, this);
  612.     
  613.     // ----- Add it -----
  614.     ::InsertMenuItem(platformMenu, "\pabc", fIndex - 1);
  615.         
  616.     ::HLock((Handle)subPlatformMenu);
  617.     ::SetMenuItemText(platformMenu, fIndex, (*subPlatformMenu)->menuData);
  618.     ::HUnlock((Handle)subPlatformMenu);
  619.     
  620.     // ----- Set the cmd key to hMenuCmd to specify sub menu
  621.     ::SetItemCmd(platformMenu, fIndex, hMenuCmd);        // has sub menu
  622.     
  623.     // ----- The menu id of the submenu is in the mark character
  624.     //     We don't set the item mark because we don't know yet the 
  625.     //    ID of the sub menu. Will be done by PrivAttachedToMenuBar.
  626. #endif
  627.  
  628. #if defined(FW_BUILD_WIN) && 0
  629.     // [jkp] need to rework menus
  630.     ::InsertMenu(platformMenu,
  631.                  fIndex,
  632.                  MF_BYPOSITION | MF_POPUP,
  633.                  (UINT) subPlatformMenu,
  634.                  subPlatformMenu.strMenu);
  635. #endif
  636. }
  637.  
  638. //----------------------------------------------------------------------------------------
  639. //    FW_CSubMenuItem::PrivFindMenuWithID
  640. //----------------------------------------------------------------------------------------
  641.  
  642. FW_CPullDownMenu* FW_CSubMenuItem::PrivFindMenuWithID(Environment* ev, ODMenuID menuID) const
  643. {
  644.     if (fSubMenu->GetMenuID(ev) == menuID)
  645.         return fSubMenu;
  646.     else 
  647.         return fSubMenu->PrivFindMenuWithID(ev, menuID);
  648. }
  649.  
  650. //----------------------------------------------------------------------------------------
  651. //    FW_CSubMenuItem::PrivGetMenuItem
  652. //----------------------------------------------------------------------------------------
  653.  
  654. FW_CMenuItem* FW_CSubMenuItem::PrivGetMenuItem(Environment* ev, ODCommandID commandID) const
  655. {
  656.     return fSubMenu->PrivGetMenuItem(ev, commandID);
  657. }
  658.  
  659. //----------------------------------------------------------------------------------------
  660. //    FW_CSubMenuItem::PrivDisableAll
  661. //----------------------------------------------------------------------------------------
  662.  
  663. void FW_CSubMenuItem::PrivDisableAll(Environment* ev)
  664. {
  665. //    FW_CMenuItem::PrivDisableAll(ev);
  666.     
  667.     fSubMenu->DisableAll(ev);
  668. }
  669.  
  670. //----------------------------------------------------------------------------------------
  671. //    FW_CSubMenuItem::PrivEnableAll
  672. //----------------------------------------------------------------------------------------
  673.  
  674. void FW_CSubMenuItem::PrivEnableAll(Environment* ev)
  675. {
  676.     FW_CMenuItem::PrivEnableAll(ev);
  677.     
  678.     fSubMenu->EnableAll(ev);
  679. }
  680.  
  681. //----------------------------------------------------------------------------------------
  682. //    FW_CSubMenuItem::PrivAttach
  683. //----------------------------------------------------------------------------------------
  684.  
  685. void FW_CSubMenuItem::PrivAttach(Environment* ev, FW_CMenuBar* menuBar)
  686. {
  687.     ODMenuID subMenuID = fSubMenu->PrivAcquireMenuID(ev, menuBar);
  688. #ifdef FW_BUILD_MAC
  689.     ::SetItemMark(fOwnerMenu->GetPlatformMenu(ev), fIndex, (FW_Char)subMenuID);
  690. #endif
  691.  
  692.     menuBar->PrivAddSubMenu(ev, subMenuID, fSubMenu->GetPlatformMenu(ev));
  693.     
  694.     fSubMenu->PrivAttach(ev, menuBar);
  695. }
  696.  
  697. //----------------------------------------------------------------------------------------
  698. //    FW_CSubMenuItem::PrivDetach
  699. //----------------------------------------------------------------------------------------
  700.  
  701. void FW_CSubMenuItem::PrivDetach(Environment* ev, FW_CMenuBar* menuBar)
  702. {
  703. #ifdef FW_BUILD_MAC
  704.     ::SetItemMark(fOwnerMenu->GetPlatformMenu(ev), fIndex, (FW_Char)0xFF);
  705. #endif
  706.     menuBar->PrivRemoveMenu(ev, fSubMenu->GetMenuID(ev));
  707.  
  708.     fSubMenu->PrivRelinquishMenuID(ev);
  709.         
  710.     fSubMenu->PrivDetach(ev, menuBar);
  711. }
  712.  
  713. //----------------------------------------------------------------------------------------
  714. //    FW_CSubMenuItem::Flatten
  715. //----------------------------------------------------------------------------------------
  716.  
  717. void FW_CSubMenuItem::Flatten(Environment* ev, FW_CWritableStream& stream)
  718. {
  719.     FW_CMenuItem::Flatten(ev, stream);
  720.     
  721.     FW_WRITE_DYNAMIC_OBJECT(stream, fSubMenu, FW_CPullDownMenu);
  722. }
  723.